import org.geotools.data.DataStoreFinder;
import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureSource;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.geojson.feature.FeatureJSON;
import org.geotools.geojson.geom.GeometryJSON;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Polygon;
import org.opengis.feature.Feature;
import org.opengis.feature.simple.SimpleFeature;

import java.awt.*;
import java.io.FileReader;
import java.io.IOException;

public class GeoJSON {
    public static void main(String[] args) throws IOException {
        FeatureJSON featureJSON = new FeatureJSON();
        FileReader fileReader = new FileReader("src/main/resources/shanghai.json");
//        FileReader fileReader = new FileReader("src/main/resources/test.json");
        SimpleFeature simpleFeature = featureJSON.readFeature(fileReader);

        DefaultFeatureCollection defaultFeatureCollection = new DefaultFeatureCollection();
        defaultFeatureCollection.add(simpleFeature);

//        DataStoreFinder dataStoreFinder = new DataStoreFinder();


        SimpleFeatureSource featureSource = DataUtilities.source(defaultFeatureCollection);
        MapContent mapContent = new MapContent();
        Style style = SLD.createPolygonStyle(new Color(255,0,0), new Color(0,255,0), 1);
        Layer layer = new FeatureLayer(featureSource, style);
        mapContent.addLayer(layer);

        JMapFrame mapFrame = new JMapFrame(mapContent);
        mapFrame.setSize(800, 600);
        mapFrame.setVisible(true);
    }
}